package com.sqf.string;

public class StringDemo2 {
    public static void main(String[] args) {
        //1.String的对象是不可变字符串对象
        //？？？
        String name = "sqf";
        name += "r1";
        name += "r2";
        System.out.println(name);

        //2.只要是"..."方式写出的字符串，会存储到字符串常量池，且相同内容的字符串只存储一份
        String s1 = "abc";
        String s2 = "abc";
        System.out.println(s1 == s2);//true
        //比较的是地址，证明s1和s2的地址相同

        //3.但通过new方式创建的字符串对象，每new一次会产生一个新的对象放在堆内存中
        char[] chars = {'a','b','c'};
        String str1 = new String(chars);
        String str2 = new String(chars);
        System.out.println(str1 == str2);//flase
    }
}
